package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.FindDetailsModle;

import java.util.Random;

/**
 * 已经没用的适配器，可是就是不想删
 * Created by lanouhn on 16/9/5.
 */
public class FindDetailsZuiLiAdapter extends RecyclerView.Adapter<FindDetailsZuiLiAdapter.MyZuiLiHolder> {

    private Context mContext;
    private FindDetailsModle.TripDaysBean.NodesBean ftnModle;

    public FindDetailsZuiLiAdapter(Context mContext, FindDetailsModle.TripDaysBean.NodesBean ftnModle) {
        this.mContext = mContext;
        this.ftnModle = ftnModle;
    }

    @Override
    public MyZuiLiHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_find_details_zuili, null);
        MyZuiLiHolder holder = new MyZuiLiHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyZuiLiHolder holder, int position) {


        if (ftnModle.getNotes().get(position).getPhoto() == null) {
            String dd = (String) ftnModle.getNotes().get(position).getDescription();

            holder.tv_duzi.setText(dd);
            holder.tv_nr.setVisibility(View.GONE);
            holder.iv.setVisibility(View.GONE);
        } else {
            if (ftnModle.getNotes().get(position).getDescription() == null) {
                holder.tv_nr.setVisibility(View.GONE);
                holder.tv_duzi.setVisibility(View.GONE);
                Picasso.with(mContext).load(ftnModle.getNotes()
                        .get(position).getPhoto().getUrl()).into(holder.iv);

            } else {

                String dd = (String) ftnModle.getNotes().get(position).getDescription();

                Picasso.with(mContext).load(ftnModle.getNotes()
                        .get(position).getPhoto().getUrl()).into(holder.iv);

                holder.tv_nr.setText(dd);
                holder.tv_duzi.setVisibility(View.GONE);
            }
        }

        Random random = new Random();
        int i = random.nextInt(70);
        holder.tv_pinglun.setText(i + "");


        if (ftnModle.getEntry_name() == null) {
            holder.ll.setVisibility(View.GONE);
        } else {
            holder.ll.setVisibility(View.VISIBLE);
            holder.tv_weizhi.setText(ftnModle.getEntry_name() + "");
        }


    }

    @Override
    public int getItemCount() {
        return ftnModle.getNotes().size();
    }

    public class MyZuiLiHolder extends RecyclerView.ViewHolder {

        private TextView tv_duzi, tv_nr, tv_pinglun, tv_weizhi;
        private ImageView iv;
        private LinearLayout ll;

        public MyZuiLiHolder(View itemView) {
            super(itemView);

            tv_duzi = (TextView) itemView.findViewById(R.id.item_find_details_zuili_duzinr);
            tv_nr = (TextView) itemView.findViewById(R.id.item_find_details_zuili_neirong);
            iv = (ImageView) itemView.findViewById(R.id.item_find_details_zuili_tupian);
            tv_pinglun = (TextView) itemView.findViewById(R.id.item_find_details_zuili_pinlunshu);
            tv_weizhi = (TextView) itemView.findViewById(R.id.item_find_details_zuili_weizhi);
            ll = (LinearLayout) itemView.findViewById(R.id.item_find_details_zuili_ll);
        }
    }

}
